
#region Using

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using WebLibs;

#endregion
namespace FEAT.Library
{
    /// <summary>
	/// Created by 		: Phan Hữu Hưng 
	/// Created date 	: 25/03/2010 
	/// Description 
	/// </summary>	
	public class ShareUserProfile
	{
	
		
	
		#region Member Variables

		private string strUsername = string.Empty;
		private string strProfilePage = string.Empty;
		private string strBlast = string.Empty;
		private bool bolIsActive;
		private DateTime dtmCreatedDate = DateTime.MinValue;
		private string strCreatedUser = string.Empty;
		private DateTime dtmUpdatedDate = DateTime.MinValue;
		private string strUpdatedUser = string.Empty;
		private bool bolIsDeleted;
		private DateTime dtmDeletedDate = DateTime.MinValue;
		private string strDeleteUser = string.Empty;
		private bool bolIsGroup;
		private IData objDataAccess = null;


		#endregion


		#region Properties 

		public static string CacheKey
		{
  			get { return  "ShareUserProfile_GetAll";}
		}
		/// <summary>
		/// Đối tượng Data truyền từ ngoài vào
		/// </summary>
		public IData DataObject
		{
  			get { return objDataAccess; }
   			set { objDataAccess = value; }
		}
		/// <summary>
		/// Username
		/// 
		/// </summary>
		public string Username
		{
			get { return  strUsername; }
			set { strUsername = value; }
		}

		/// <summary>
		/// ProfilePage
		/// 
		/// </summary>
		public string ProfilePage
		{
			get { return  strProfilePage; }
			set { strProfilePage = value; }
		}

		/// <summary>
		/// Blast
		/// 
		/// </summary>
		public string Blast
		{
			get { return  strBlast; }
			set { strBlast = value; }
		}

		/// <summary>
		/// IsActive
		/// 
		/// </summary>
		public bool IsActive
		{
			get { return  bolIsActive; }
			set { bolIsActive = value; }
		}

		/// <summary>
		/// CreatedDate
		/// 
		/// </summary>
		public DateTime CreatedDate
		{
			get { return  dtmCreatedDate; }
			set { dtmCreatedDate = value; }
		}

		/// <summary>
		/// CreatedUser
		/// 
		/// </summary>
		public string CreatedUser
		{
			get { return  strCreatedUser; }
			set { strCreatedUser = value; }
		}

		/// <summary>
		/// UpdatedDate
		/// 
		/// </summary>
		public DateTime UpdatedDate
		{
			get { return  dtmUpdatedDate; }
			set { dtmUpdatedDate = value; }
		}

		/// <summary>
		/// UpdatedUser
		/// 
		/// </summary>
		public string UpdatedUser
		{
			get { return  strUpdatedUser; }
			set { strUpdatedUser = value; }
		}

		/// <summary>
		/// IsDeleted
		/// 
		/// </summary>
		public bool IsDeleted
		{
			get { return  bolIsDeleted; }
			set { bolIsDeleted = value; }
		}

		/// <summary>
		/// DeletedDate
		/// 
		/// </summary>
		public DateTime DeletedDate
		{
			get { return  dtmDeletedDate; }
			set { dtmDeletedDate = value; }
		}

		/// <summary>
		/// DeleteUser
		/// 
		/// </summary>
		public string DeleteUser
		{
			get { return  strDeleteUser; }
			set { strDeleteUser = value; }
		}

		/// <summary>
		/// IsGroup
		/// 
		/// </summary>
		public bool IsGroup
		{
			get { return  bolIsGroup; }
			set { bolIsGroup = value; }
		}


		#endregion		
		
		
		#region Constructor

		public ShareUserProfile()
		{
		}
		private static ShareUserProfile _current;
		static ShareUserProfile()
		{
			_current = new ShareUserProfile();
		}
		public static ShareUserProfile Current
		{
			get
			{
		      return _current;
			}
		}
		#endregion

		#region Methods	



		///<summary>
		/// Kiểm tra xem đối tượng có dữ liệu hay không
		///</summary>
		/// <returns>true ? Có : False ? Không</returns>
		public bool LoadByPrimaryKeys()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			bool bolOK = false;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserProfile_Select");
				objData.AddParameter("@Username", this.Username);
				IDataReader reader = objData.ExecStoreToDataReader();
				if (reader.Read())
 				{
					if(!this.IsDBNull(reader["Username"]))	this.Username = Convert.ToString(reader["Username"]);
					if(!this.IsDBNull(reader["ProfilePage"]))	this.ProfilePage = Convert.ToString(reader["ProfilePage"]);
					if(!this.IsDBNull(reader["Blast"]))	this.Blast = Convert.ToString(reader["Blast"]);
					if(!this.IsDBNull(reader["IsActive"]))	this.IsActive = Convert.ToBoolean(reader["IsActive"]);
					if(!this.IsDBNull(reader["CreatedDate"]))	this.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]);
					if(!this.IsDBNull(reader["CreatedUser"]))	this.CreatedUser = Convert.ToString(reader["CreatedUser"]);
					if(!this.IsDBNull(reader["UpdatedDate"]))	this.UpdatedDate = Convert.ToDateTime(reader["UpdatedDate"]);
					if(!this.IsDBNull(reader["UpdatedUser"]))	this.UpdatedUser = Convert.ToString(reader["UpdatedUser"]);
					if(!this.IsDBNull(reader["IsDeleted"]))	this.IsDeleted = Convert.ToBoolean(reader["IsDeleted"]);
					if(!this.IsDBNull(reader["DeletedDate"]))	this.DeletedDate = Convert.ToDateTime(reader["DeletedDate"]);
					if(!this.IsDBNull(reader["DeleteUser"]))	this.DeleteUser = Convert.ToString(reader["DeleteUser"]);
					if(!this.IsDBNull(reader["IsGroup"]))	this.IsGroup = Convert.ToBoolean(reader["IsGroup"]);
 					bolOK = true;
 				}
				reader.Close();
			}
			catch (Exception objEx)
			{
				throw new Exception("LoadByPrimaryKeys() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return bolOK;
		}

		///<summary>
		/// Insert : Share_UserProfile
		/// Them moi du lieu
		///</summary>
		public object Insert()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserProfile_Insert");
				objData.AddParameter("@Username", this.Username);
				objData.AddParameter("@ProfilePage", this.ProfilePage);
				objData.AddParameter("@Blast", this.Blast);
				objData.AddParameter("@IsActive", this.IsActive);
				objData.AddParameter("@CreatedUser", this.CreatedUser);
				objData.AddParameter("@DeleteUser", this.DeleteUser);
				objData.AddParameter("@IsGroup", this.IsGroup);
                objTemp = objData.ExecStoreToString();
			}
			catch (Exception objEx)
			{
				throw new Exception("Insert() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Update : Share_UserProfile
		/// Cap nhap thong tin
		///</summary>
		public object Update()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserProfile_Update");
				objData.AddParameter("@Username", this.Username);
				objData.AddParameter("@ProfilePage", this.ProfilePage);
				objData.AddParameter("@Blast", this.Blast);
				objData.AddParameter("@IsActive", this.IsActive);
				objData.AddParameter("@UpdatedUser", this.UpdatedUser);
				objData.AddParameter("@DeleteUser", this.DeleteUser);
				objData.AddParameter("@IsGroup", this.IsGroup);
                objTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Update() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Delete : Share_UserProfile
		///
		///</summary>
		public int Delete()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			int intTemp = 0;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserProfile_Delete");
				objData.AddParameter("@Username", this.Username);
 				intTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Delete() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return intTemp;
		}


		///<summary>
		/// Get all : Share_UserProfile
		///
		///</summary>
		public DataTable GetAll()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			try
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("Share_UserProfile_SelectAll");
				return objData.ExecStoreToDataTable();
			}
			catch (Exception objEx)
			{
				throw new Exception("GetAll() Error   " + objEx.Message.ToString());
			}
			finally
			{
    		 if (objDataAccess == null)
        		objData.DeConnect();
			}
		}
		#endregion


		/// <summary>
        /// Check Data IsDBNull 
        /// </summary>
        /// <param name="objObject"> Object Value</param>
        /// <returns>Null : true ? false </returns>
		private bool IsDBNull(object objObject)
		{
			return Convert.IsDBNull(objObject);
		}
		
		
		/******************************************************
		 	Share_UserProfile objShare_UserProfile = new Share_UserProfile();
			objShareUserProfile.Username = txtUsername.Text;
			objShareUserProfile.ProfilePage = txtProfilePage.Text;
			objShareUserProfile.Blast = txtBlast.Text;
			objShareUserProfile.IsActive = txtIsActive.Text;
			objShareUserProfile.CreatedDate = txtCreatedDate.Text;
			objShareUserProfile.CreatedUser = txtCreatedUser.Text;
			objShareUserProfile.UpdatedDate = txtUpdatedDate.Text;
			objShareUserProfile.UpdatedUser = txtUpdatedUser.Text;
			objShareUserProfile.IsDeleted = txtIsDeleted.Text;
			objShareUserProfile.DeletedDate = txtDeletedDate.Text;
			objShareUserProfile.DeleteUser = txtDeleteUser.Text;
			objShareUserProfile.IsGroup = txtIsGroup.Text;

		 
		 ******************************************************
		 
		 			txtUsername.Text = objShareUserProfile.Username;
			txtProfilePage.Text = objShareUserProfile.ProfilePage;
			txtBlast.Text = objShareUserProfile.Blast;
			txtIsActive.Text = objShareUserProfile.IsActive;
			txtCreatedDate.Text = objShareUserProfile.CreatedDate;
			txtCreatedUser.Text = objShareUserProfile.CreatedUser;
			txtUpdatedDate.Text = objShareUserProfile.UpdatedDate;
			txtUpdatedUser.Text = objShareUserProfile.UpdatedUser;
			txtIsDeleted.Text = objShareUserProfile.IsDeleted;
			txtDeletedDate.Text = objShareUserProfile.DeletedDate;
			txtDeleteUser.Text = objShareUserProfile.DeleteUser;
			txtIsGroup.Text = objShareUserProfile.IsGroup;

		 
		*******************************************************/
		
	}
}
